/* 
 * File:   url.cpp
 * Author: Faraj
 * 
 * Created on May 11, 2013, 4:31 PM
 */
#include "url.h"

lib::url::url(string url) {
    common::log::trace("url.url");
    if(url.at(0) != '/'){        
        url = "/" + url;
    }    
    if(common::str::contains("?", url)){
        vector<string> query_arr = common::str::explode("?", url);
        _path = query_arr[0];
        _query = query_arr[1];
    }else{
        _path = url;
        _query = "";
    }
    vector<string> path_arr = common::str::explode("/", _path);
    if(path_arr.size() > 2){
        _base = path_arr[1];
        _path = common::str::replace(_path,  "/" + _base + "/", "");
    }else{
        _base = "web";
        _path = _path.substr(1, _path.size());
    }
}

string lib::url::get_path(){
    return _path;
}

string lib::url::get_file_path(){
    common::log::trace("url.get_file_path");
    return common::str::replace_all(_path, "/", common::os::dir_seperator());
}

string lib::url::get_query(){
    return _query;
}

string lib::url::get_base(){
    return _base;
}

lib::url::~url(){
    common::log::trace("url.~url");
}